﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework;

namespace BostonXNA.InputHandling.Input
{
	abstract class InputActivity : IInputActivity
	{
		public abstract bool Check( InputState state );
	}

	class KeyUpActivity : InputActivity
	{
		public Keys Key = Keys.None;

		public override bool Check( InputState state )
		{
			return state.Keyboard.Current.IsKeyUp( Key );
		}
	}

	class KeyDownActivity : InputActivity
	{
		public Keys Key;

		public override bool Check( InputState state )
		{
			return state.Keyboard.Current.IsKeyDown( Key );
		}
	}

	class MouseMoveActivity : InputActivity
	{
		public MouseMove Direction;

		public override bool Check( InputState state )
		{
			Vector2 movement;			
			movement.X = state.Mouse.Current.X - state.Mouse.Previous.X; // - == Left
			movement.Y = state.Mouse.Current.Y - state.Mouse.Previous.Y; // - == Down
			if (	( movement.X > 0 && Direction == MouseMove.Right )  // moving Right
				 || ( movement.X < 0 && Direction == MouseMove.Left )  // moving Left
				 || ( movement.Y < 0 && Direction == MouseMove.Up ) // moving on Up
				 || ( movement.Y > 0 && Direction == MouseMove.Down ) // going Down (town) 
			   )
			{
				return true;
			}
			return false;
		}
	}

	class MouseButtonDownActivity : InputActivity
	{
		Buttons Button;

		public override bool Check( InputState state )
		{
			return false;
		}
	}

	class MouseButtonUpActivity : InputActivity
	{
		Buttons Button;

		public override bool Check( InputState state )
		{
			return false;
		}
	}

	class GamePadButtonDownActivity : InputActivity
	{
		public Buttons Button;
		public override bool Check( InputState state )
		{
			return state.GamePad.Current.IsButtonDown( Button );
		}
	}

	class GamePadButtonUpActivity : InputActivity
	{
		public Buttons Button;
		public override bool Check( InputState state )
		{
			return state.GamePad.Current.IsButtonUp( Button );
		}
	}

	public enum ThumbStick
	{
		Left,
		Right
	}
	class GamePadThumbstickActivity : InputActivity
	{
		public ThumbStick ThumbStick;
		public override bool Check( InputState state )
		{
			switch( ThumbStick )
			{
				case ThumbStick.Left:
					return state.GamePad.Current.ThumbSticks.Left != Vector2.Zero;
				case ThumbStick.Right:
					return state.GamePad.Current.ThumbSticks.Right != Vector2.Zero;
			}
			return false;
		}
	}
}
